﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using System.Windows;
using System.Windows.Data;
using System.Text.RegularExpressions;
using FinPlusInterfaces;

namespace FinPlusCompView
{
    public class FinPlusGridColShift : FinPlusGridColBase
    {
        [State(Test = true)]
        public override bool IsValid { get; set; }

        //construct
        public FinPlusGridColShift(string name, string stringFormat, string links, string inputMask, bool isEnabled = false)
        {
            var tb = new FrameworkElementFactory(typeof(FinPlusValueShiftTextBox));
            tb.SetBinding(FinPlusValueShiftTextBox.IdProperty, new Binding(BeanField.Id.ToString()) { Mode = BindingMode.OneWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged });
            tb.SetBinding(FinPlusValueShiftTextBox.ValueProperty, new Binding(BeanField.Value.ToString()) { Mode = BindingMode.OneWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged });
            tb.SetBinding(FinPlusValueShiftTextBox.TextProperty, new Binding(name) { StringFormat = stringFormat, Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged });
            tb.SetBinding(FinPlusValueShiftTextBox.StepProperty, new Binding(links) { Mode = BindingMode.OneWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged });
            tb.SetValue(FinPlusValueShiftTextBox.IsEnabledProperty, isEnabled);
            tb.SetValue(FinPlusValueShiftTextBox.StringFormatProperty, stringFormat);
            tb.SetValue(FinPlusValueShiftTextBox.InputMaskProperty, new Regex(inputMask));
            var et = new DataTemplate() { VisualTree = tb };

            var dt = TextBlockCell(name, stringFormat, "Num");

            Header = HeaderTextBlock(name, "SUpDown");
            ClipboardContentBinding = new Binding(name) { Mode = BindingMode.OneWay };
            CellEditingTemplate = et;
            CellTemplate = dt;
            CanUserSort = true;
        }
    }
}
